package cn.edu.hatu.bookshop.controller;

import cn.edu.hatu.bookshop.entity.Customer;
import cn.edu.hatu.bookshop.service.CustomerService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.context.annotation.RequestScope;

import javax.servlet.http.HttpServletRequest;

@Controller
public class RegisterController {
    private CustomerService customerService;
    @Autowired
    public void setCustomerService(CustomerService customerService) {
        this.customerService = customerService;
    }
    @RequestMapping("/registerInput")
    public String registerInput(){
        return "Customer/Register";
    }
    @RequestMapping("/registerCheck")
    public String registerCheck(HttpServletRequest request){
        String username = request.getParameter("username").trim();
        String password = request.getParameter("password").trim();
        String address = request.getParameter("address").trim();
        String email = request.getParameter("email").trim();
        String telephone = request.getParameter("telephone").trim();
        Customer customer = new Customer(password,username,address,email,telephone);
        customerService.addCustomer(customer);
        return "redirect:loginInput";
    }


}
